package com.linkage.yninterface.util.config.operationconfig;

/**
 * <p>Title: yninterface</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: linkage</p>
 *
 * @author weibo
 * @version 1.0
 */
import java.io.File;
import java.util.HashMap;
import java.util.List;

import com.linkage.yninterface.util.ConfigUtil;
import com.linkage.yninterface.util.parse.parseXMLObject;

public class processConfFactory {

	public static HashMap processConfs;
	public static List lio;

	public processConfFactory(String operationFile) throws Exception {
		processConfs = new HashMap();
		parseXMLObject parsexmlobject = new parseXMLObject(
				"com.linkage.yninterface.util.config.operationconfig");
		lio = parsexmlobject.getListFromXML(operationFile, operation.class,
				"operations");
		String projectMainDir = new File(ConfigUtil.classPath).getParent()
				+ "../../";// zhaigxadd
		for (int i = 0; i < lio.size(); i++) {
			operation op = (operation) lio.get(i);

			List lit = parsexmlobject.getListFromXML(
					projectMainDir + op.getDealPath(), transobject.class,
					"processinfo/transobjects");
			HashMap transObjects = new HashMap();
			for (int j = 0; j < lit.size(); j++) {
				transobject t = (transobject) lit.get(j);
				t.setPc(Class.forName(t.getClassname()));
				transObjects.put(t.getName(), t);
			}

			List lid = parsexmlobject.getListFromXML(
					projectMainDir + op.getDealPath(), deal.class,
					"processinfo/deals");
			for (int j = 0; j < lid.size(); j++) {

				deal dl = (deal) lid.get(j);
				processConf pc = new processConf(op, dl, transObjects);

				// System.out.println(pc.getOperationType()+"@@@"+pc.getDealType()+"="+
				// dl.getParseObjects().size());

				processConfs.put(
						pc.getOperationType() + "@@@" + pc.getDealType(), pc);
			}
		}

	}

	public static processConf getProcessConfByKey(String type) {
		Object o = processConfs.get(type);

		if (o == null)
			return null;
		else
			return (processConf) o;
	}

	public static HashMap getProcessConfs() {
		return processConfs;
	}

	// public static void main(String[] args) {
	// try {
	// processConfFactory pcf = new processConfFactory(
	// "D:\\project\\ynInterfaceFinal\\config\\operationConf.xml");
	//
	//
	// System.out.println(".>"+processConfFactory.getProcessConfs().size());
	// processConf pp= processConfFactory.getProcessConfByKey("3@@@1");
	// System.out.println(">>"+((parseObject)pp.getParseObjects().get(0)).getParseFieldDes());
	//
	// }
	// catch (Exception ex) {
	// ex.printStackTrace();
	// }
	//
	// }
}
